<?php require_once('../Connections/conexion.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tubo (COD_TUBO, COD_GRAFICADOR, NOMBRE_TUBO, MATERIAL_TUBO, DIAMETRO_TUBO) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['COD_TUBO'], "int"),
                       GetSQLValueString($_POST['COD_GRAFICADOR'], "int"),
                       GetSQLValueString($_POST['NOMBRE_TUBO'], "text"),
                       GetSQLValueString($_POST['MATERIAL_TUBO'], "text"),
                       GetSQLValueString($_POST['DIAMETRO_TUBO'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = "nuevo_tubo.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$maxRows_tubos = 10;
$pageNum_tubos = 0;
if (isset($_GET['pageNum_tubos'])) {
  $pageNum_tubos = $_GET['pageNum_tubos'];
}
$startRow_tubos = $pageNum_tubos * $maxRows_tubos;

mysql_select_db($database_conexion, $conexion);
$query_tubos = "SELECT COD_TUBO, NOMBRE_TUBO, MATERIAL_TUBO, DIAMETRO_TUBO FROM tubo ORDER BY COD_TUBO ASC";
$query_limit_tubos = sprintf("%s LIMIT %d, %d", $query_tubos, $startRow_tubos, $maxRows_tubos);
$tubos = mysql_query($query_limit_tubos, $conexion) or die(mysql_error());
$row_tubos = mysql_fetch_assoc($tubos);

if (isset($_GET['totalRows_tubos'])) {
  $totalRows_tubos = $_GET['totalRows_tubos'];
} else {
  $all_tubos = mysql_query($query_tubos);
  $totalRows_tubos = mysql_num_rows($all_tubos);
}
$totalPages_tubos = ceil($totalRows_tubos/$maxRows_tubos)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/principal1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Registro de Tubo</title>
<!-- InstanceEndEditable -->
<link href="../styles/estilos.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" -->
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<!-- InstanceEndEditable -->
</head>
<body>
        <div id="contenedor">
                <div id="cabecera">
                  <div align="right"><!-- InstanceBeginEditable name="menu_superior" -->
                  
                  menu_superior<!-- InstanceEndEditable -->
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                  </div>
                </div>
                <div id="barra-lateral">
                  <div align="justify"><!-- InstanceBeginEditable name="menu" -->
				  <div class="boton1">
				  <a href="nuevo_proyecto.php">Nuevo Proyecto</a></div>
				  <div class="boton2">
				  <a href="nueva_bomba.php">Registrar Bomba</a>				  </div>
				  <div class="boton3">
				  <a href="nuevo_tubo.php">Registrar Tubo</a>				  </div>
				  <div class="boton4">
				  <a href="nuevo_filtro.php">Registrar Filtro</a>				  </div>
				  <div class="boton5">
				  <a href="nueva_litologia.php">Registrar Litologia</a>				  </div>
				  <!-- InstanceEndEditable --></div>
                </div>
                   <div id="contenido"> 
                     <div align="justify"><!-- InstanceBeginEditable name="cuerpo" -->
                       
  <fieldset>
  <legend><font size="+1">Registrar Nuevo Tubo </legend>
  <div>
   <form action="<?php echo $editFormAction; ?>" method="post" name="form1" onsubmit="MM_validateForm('NOMBRE_TUBO','','R','MATERIAL_TUBO','','R','DIAMETRO_TUBO','','R');return document.MM_returnValue">
                    <table align="center">
                      <tr valign="baseline">
                        <td nowrap align="right">NOMBRE DE TUBO:</td>
                        <td><input type="text" name="NOMBRE_TUBO" value="" size="32"></td>
                      </tr>
                      <tr valign="baseline">
                        <td nowrap align="right">MATERIAL:</td>
                        <td><input type="text" name="MATERIAL_TUBO" value="" size="32"></td>
                      </tr>
                      <tr valign="baseline">
                        <td nowrap align="right">DIAMETRO:</td>
                        <td><input type="text" name="DIAMETRO_TUBO" value="" size="32"></td>
                      </tr>
                      <tr valign="baseline">
                        <td nowrap align="right">&nbsp;</td>
                        <td><input type="submit" value="Insertar registro"></td>
                      </tr>
                    </table>
                    <input type="hidden" name="COD_TUBO" value="">
                    <input type="hidden" name="COD_GRAFICADOR" value="<?php echo $row_Recordset1['COD_GRAFICADOR']; ?>">
                    <input type="hidden" name="MM_insert" value="form1">
        </form>
                  <p>&nbsp;</p>
  </div>
  </fieldset>
  <br>
  <fieldset>
  <legend><font size="+1">Registrar Nuevo Tubo </legend>
  <div>
  
    <table border="1" cellpadding="1" cellspacing="1" align="center">
      <tr>
	  	<td>CODIGO</td>
        <td>NOMBRE TUBO</td>
        <td>MATERIAL</td>
        <td>DIAMETRO</td>
      </tr>
      <?php do { ?>
        <tr>
		  <td><?php echo $row_tubos['COD_TUBO']; ?></td>
          <td><?php echo $row_tubos['NOMBRE_TUBO']; ?></td>
          <td><?php echo $row_tubos['MATERIAL_TUBO']; ?></td>
          <td><?php echo $row_tubos['DIAMETRO_TUBO']; ?></td>
        </tr>
        <?php } while ($row_tubos = mysql_fetch_assoc($tubos)); ?>
    </table>
	<p>&nbsp;</p>
  </div>
  </fieldset>

                     <!-- InstanceEndEditable --> </div>
                   </div>
                   <div id="pie">
				   <table width="100%" border="1" cellspacing="1" cellpadding="1">
  <tr>
    <td><span class="Estilo4"><a href="http://www.javier.com.co/terminos/">T&eacute;rminos y Condiciones de Uso</a> |</span></td>
    <td><span class="Estilo4">Copyright&copy;  Todos los derechos reservados - Desarrollado por <a href="http://www.Javier.com/" target="_blank" title="Javier">JAVIER T. </a></span></td>
    <td><span class="Estilo4"><a href="http://www.javier_tola.com>Ayuda</a> | </span></td>
    <td><a href=../Templates/%22http://www.javier_tola.com" class="Estilo4">Cont&aacute;cteme</a></td>
  </tr>
</table></div>
       </div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($tubos);
?>